#include"mq_connection.hpp"

int main()
{
    //1.实例化异步工作线程对象
    xiang11mq::AsyncWorker::ptr awp = std::make_shared<xiang11mq::AsyncWorker>();
    //2.实例化连接对象
    xiang11mq::Client::ptr conn = std::make_shared<xiang11mq::Client>("127.0.0.1", 8888, awp);
    //3.通过连接创建对象
    xiang11mq::Channel::ptr channel = conn->openChannel();
    //4.通过信道提供的服务完成所需
    // 1.声明一个交换机exchange1，交换机类型为广播模式
    google::protobuf::Map<std::string, std::string> tmp_map;
    channel->declareExchange("exchange1", xiang11mq::ExchangeType::TOPIC, true, false, tmp_map);
    // 2.声明一个队列queue1
    channel->declareQueue("queue1", true, false, false, tmp_map);
    // 3.声明一个队列queue2
    channel->declareQueue("queue2", true, false, false, tmp_map);
    // 4.绑定queue1-exchange1，且binding key设置为queue1
    channel->queueBind("exchange1", "queue1", "queue1");
    // 5.绑定queue2-exchange1，且binding key设置为news.music.#
    channel->queueBind("exchange1", "queue2", "news.music.#");
    // 5.循环向交换机发布消息
    for(int i = 0; i < 10; i ++)
    {
        xiang11mq::BasicProperties bp;
        bp.set_id(xiang11mq::UUIDHelper::uuid());
        bp.set_deliver_mode(xiang11mq::DeliverMode::DURABLE);
        bp.set_routing_key("news.music.pop");
        channel->basicPublic("exchange1", &bp, ("Hello music-pop" + std::to_string(i)));
    }
        xiang11mq::BasicProperties bp;
        bp.set_id(xiang11mq::UUIDHelper::uuid());
        bp.set_deliver_mode(xiang11mq::DeliverMode::DURABLE);
        bp.set_routing_key("news.music.classical");
        channel->basicPublic("exchange1", &bp, "Hello music-classical");

        bp.set_id(xiang11mq::UUIDHelper::uuid());
        bp.set_deliver_mode(xiang11mq::DeliverMode::DURABLE);
        bp.set_routing_key("news.sport");
        channel->basicPublic("exchange1", &bp, "Hello sport");
    // 6.关闭信道
    DLOG("生产者客户端连接关闭 channeID: %s ", channel->cid().c_str());
    conn->closeChannel(channel);
    // 7.关闭连接


    return 0;
}